package com.example.team.controller;

import com.example.team.entity.User;
import com.example.team.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 作者：代志雄
 * 2023年11月3日11点10分
 */
@RestController
@Api(tags = "用户管理")
public class UserController {
    @Autowired
    private IUserService user1Service;

    @ApiOperation(value = "添加用户",
            notes = "成功返回1")
    @RequestMapping(value="/insertUser1",method = {RequestMethod.GET})
    public int insertUser1(String name,String password,String email){
        User user1=new User();
        user1.setUserName(name);
        user1.setUserPasswoed(password);
        user1.setEmail(email);
        return user1Service.insertUser1(user1);
    }

    @ApiOperation(value = "删除用户",
            notes = "成功返回1")
    @RequestMapping(value="/deleteUser1",method = {RequestMethod.GET})
    public int deleteUser1(int id){
        User user1=new User();
        user1.setUserId(id);
        return user1Service.deleteUser1(user1);
    }

    @ApiOperation(value = "修改用户信息",
            notes = "成功返回1")
    @RequestMapping(value="/updateUser1",method = {RequestMethod.GET})
    public int updateUser1(User user1){
        return user1Service.updateUser1(user1);
    }

    @ApiOperation(value = "查询所有用户信息",
            notes = "成功返回Json")
    @RequestMapping(value="/getAllUser1",method = {RequestMethod.GET})
    public List<User> getAllUser1(String name){
        User user1=new User();
        user1.setUserName(name);
        return user1Service.getAllUser1(user1);
    }

    @ApiOperation(value = "查询用户信息",
            notes = "成功返回Json")
    @RequestMapping(value="/getUser1",method = {RequestMethod.GET})
    public User getUser1(String name){
        User user1=new User();
        user1.setUserName(name);
        return user1Service.getUser1(user1);
    }
}